<?php
declare (strict_types = 1);

namespace app\auth\model;

use think\Model;

/**
 * @mixin think\Model
 */
class Admin extends Model
{
    // 定义时间戳字段名
    protected $createTime = 'reg_time';
    protected $updateTime = 'update_time';
    public function getPasswordAttr($value)
    {
        return '';
    }
    public function getSaltAttr($value)
    {
        return '';
    }
    public function setUsernameAttr($username)
    {
        return trim($username);
    }
    public function setTruenameAttr($truename){
        return trim($truename);
    }
    // 保存管理员最后登陆时间
    public function setLastLoginTime($username)
    {
        return $this->where('username',$username)->setField('lastlogin_time',time());
    }
    public function getLastloginTimeAttr($value)
    {
        return  empty($value)?'未登录':date('Y-m-d H:i:s', $value);
    }
    // 用户头像
    public function getAvatarAttr($value,$data){
        return !empty($value) ? $value: 'https://cdn.vuetifyjs.com/images/parallax/material.jpg';
    }
}
